package com.wc._16届国特冲刺营._09_数据结构_线段树屠龙术.仪仗队;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/31 16:28
 * @description
 * https://www.lanqiao.cn/courses/51805/learning/?id=4072921&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 线段树维护最短值坐标
     * 二分查找前缀和的个数, 包含删除的
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 500010, M = N << 2;
    static int[] minv = new int[M], idx = new int[M], num = new int[M];
    static long[] sum = new long[M];
    static int[] a = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        build(1, 1, n);
        m = sc.nextInt();
        while (m-- > 0) {
            int l = sc.nextInt(), r = sc.nextInt();
            l = get(l);
            r = get(r);
            int idx = query(1, 1, n, l, r);
            a[idx] = 0;
            update(1, 1, n, idx);
        }
        out.println(sum[1]);
        out.flush();
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            sum[u] = minv[u] = a[l];
            idx[u] = l;
            num[u] = 1;
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l , mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        int l = u << 1, r = u << 1 | 1;
        sum[u] = sum[l] + sum[r];
        num[u] = num[l] + num[r];
        if (idx[l] == 0) {
            idx[u] = idx[r];
            minv[u] = minv[r];
        } else if (idx[r] == 0) {
            idx[u] = idx[l];
            minv[u] = minv[l];
        } else {
            if (minv[l] <= minv[r]) {
                idx[u] = idx[l];
                minv[u] = minv[l];
            } else {
                idx[u] = idx[r];
                minv[u] = minv[r];
            }
        }
    }

    static int get(int x) {
        int l = 1, r = n;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid, x)) r = mid;
            else l = mid + 1;
        }
        return r;
    }

    static boolean check(int x, int num) {
        return queryNum(1, 1, n, 1, x) >= num;
    }

    static int queryNum(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) return num[u];

        int mid = l + r >> 1;
        if (qr <= mid) return queryNum(u << 1, l, mid, ql, qr);
        if (ql > mid) return queryNum(u << 1 | 1, mid + 1, r, ql, qr);
        int L = queryNum(u << 1, l, mid, ql, mid);
        int R = queryNum(u << 1 | 1, mid + 1, r, mid + 1, qr);
        return L + R;
    }

    static int query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) return idx[u];

        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        int L = query(u << 1, l, mid, ql, mid);
        int R = query(u << 1 | 1, mid + 1, r, mid + 1, qr);
        // 细节决定成败
        if (L == 0) return R;
        if (R == 0) return L;
        return a[L] <= a[R] ? L : R;
    }

    static void update(int u, int l, int r, int x) {
        if (l == r) {
            num[u]  = idx[u] = minv[u] = 0;
            sum[u] = 0;
            return;
        }
        int mid = l + r >> 1;
        if (x <= mid) update(u << 1, l, mid, x);
        else update(u << 1 | 1, mid + 1, r, x);
        pushUp(u);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

